import 'package:flutter/material.dart';
import 'package:study_demo/base/theme_controller.dart';

enum Orientation { horizontal, vertical }

class Navi extends StatefulWidget {
  int selectedIndex;
  Color selectedColor;
  List<IconData> icons;
  List<String> data;
  double space;
  Function? onPressed;
  Orientation? orientation;

  Navi(
    this.icons,
    this.data, {
    this.orientation = Orientation.vertical,
    this.selectedIndex = 0,
    this.selectedColor = Colors.deepPurpleAccent,
    this.space = 5,
    this.onPressed,
  });

  @override
  _NaviState createState() => _NaviState();
}

class _NaviState extends State<Navi> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        scrollDirection: widget.orientation == Orientation.vertical
            ? Axis.vertical
            : Axis.horizontal,
        itemCount: widget.data.length,
        itemBuilder: (BuildContext context, int index) {
          return itemLayout(index);
        });
  }

  itemLayout(int index) {
    final iconData = widget.icons[index];
    final color = widget.selectedIndex == index
        ? widget.selectedColor
        : (isDarkMode.value ? Colors.grey : Colors.black);
    return Container(
        height: 70,
        alignment: Alignment.center,
        child: InkWell(
            onTap: () {
              setState(() {
                widget.selectedIndex = index;
              });
              widget.onPressed?.call(index);
            },
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Icon(iconData, color: color),
                SizedBox(
                  height: widget.space,
                ),
                Text(
                  widget.data[index],
                  style: TextStyle(color: color),
                )
              ],
            )));
  }
}
